package data.generators;

import data.stock.NewsCorpus;
import data.stock.NewsStory;

/**
 * The ContextCorpusGenerator generates a news corpus with nonsense words chosen
 * to reflect the influence of the news article.  Articles exhibit the following:
 * constant intervals of time, whose time-frame is constant, and whose influence
 * is a random number [-1,1]
 * @author Kevin Dolan
 *
 */
public class ContextCorpusGenerator implements CorpusGenerator {

	private String[] goodWords = {"keyboard","sentinel","paint","diamond","lollipop","candy","mcdonalds","burger","king","dairy","queen","lizard","tray","airplane","dash","boeing","cessna","interruption","exception","ajax","comet","blanket","suit","barney","stinson","how","mother","met","trifle","tag","tad","rad","sad","awful","frost","frostful","running","exercise","nutrition","epilepsy","argument","intelligence","stupidity","rigidity","fluidity","singuinity","crassness","jackass","pornography","fellowship"};
	private String[] badWords = {"suicide","homicide","rape","murder","crime","pollution","environment","darkness","love","loveliness","beauty","lust","jealousy","rage","smell","feet","lips","birds","dinosaurs","space","stars","raging","pillow","sex","sexual","freud","gertrude","networks","edges","nodes","prison","marijuana","belt","woe","hamlet","ford","mustang","chevy","tahoe","intrepid","fearless","rapid","agile","extreme","pitiful","piteous","prejudge","crimson","elephant","mouse"};
	private String[] neutralWords = {"moose","cow","spinal","tap","is","going","in","running","all","camera","internet","space","kevin","god","frighten","toll","england","antwerp","pollack","final","camera","toothpick","snippet","frangle","droid","google","aerosmith","dungen","castles","starcastles","word","list","parking","violation","slime","nickelodeon","jordan","michael","bad","good","rent","simultaneous","excretion","only","shamwow","vince","volume","melatonin","pfizer","nextjump"};
	
	private double neutralProportion;
	private int maxWords, timeStep, timeFrame, numStories;
	
	public ContextCorpusGenerator(double neutralProportion, int maxWords, int timeStep, int timeFrame, int numStories) {
		this.neutralProportion = neutralProportion;
		this.maxWords = maxWords;
		this.timeStep = timeStep;
		this.timeFrame = timeFrame;
		this.numStories = numStories;
	}
	
	@Override
	public NewsCorpus generate() {
		NewsCorpus corpus = new NewsCorpus();
		long time = 0;
		for(int i = 0; i < numStories; i++) {
			double positive = Math.random();
			double influence = positive * 2 - 1;
			
			StringBuffer sb = new StringBuffer();
			int numWords = (int) (Math.random() * maxWords);
			for(int j = 0; j < numWords; j++) {
				String[] wordList;
				if(Math.random() < neutralProportion)
					wordList = neutralWords;
				else if(Math.random() < positive)
					wordList = goodWords;
				else
					wordList = badWords;
				sb.append(wordList[(int) (Math.random() * 50)] + " ");
			}
			
			NewsStory story = new NewsStory(time, "Context Corpus Generator", 
					"News Story #"+i, "LINEAR;"+influence+";"+timeFrame, sb.toString());
			
			corpus.addNews(story);
			time += timeStep;
		}		
		return corpus;
	}

}
